<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>添加代理商</title>
</head>
<body class="layui-layout-body">
 <link rel="stylesheet" href="/asset/plugin/formSelects/dist/formSelects-v4.css">
<div class="layui-body">
        <!-- 内容主体区域 -->
        <div class="body_right">
            <h4 class="nav_title">代理商添加</h4>
            
            <form class="layui-form">
            		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
				  <legend>公司信息</legend>
				</fieldset>
                 <div class="layui-form-item">
                    <label for="companyType" class="layui-form-label">企业类型：</label>
                    <div class="layui-input-inline">
                        <select id="companyType" name="companyType" lay-filter="companyType">
                            <option value="0" selected="">企业</option>
                            <option value="1">个体</option>
                            <option value="2">政府机关</option>
                        </select>
                    </div>
                		<div class="layui-form-mid layui-word-aux">
	                  <span class="x-red">*</span>
	              </div>
                </div>
                <div class="layui-form-item">
                    <label for="companyName" class="layui-form-label ">企业名称:</label>
                    <div class="layui-input-inline" style="width:400px">
                        <input type="text" id="companyName" name="companyName" required="  lay-verify="companyName"   autocomplete="off" class="layui-input" placeholder="请输入公司名称">
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label for="creditCode" class="layui-form-label"></label>
                    <div class="layui-input-inline layui-word-aux" style="width: 300px;">
                     请填写工商营业执照上的企业全称
                    </div>
                </div>
                
                <div class="layui-form-item">
                    <label for="companyName" class="layui-form-label ">所在地区:</label>
                    <div class="layui-input-inline" style="width: 400px;">
	                      <select name="geos" xm-select="select15_2" xm-select-radio="">
					         <option value="">请选择公司所在地区</option>
					      </select>
                    </div>
                </div>
                
                
                <div class="layui-form-item">
                    <label for="creditCode" class="layui-form-label">统一信用代码:</label>
                    <div class="layui-input-inline" style="width: 300px;">
                        <input type="text" id="creditCode" name="creditCode" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入统一信用代码">
                    </div>
                    
                </div>
                
                <div class="layui-form-item">
                    <label for="creditCode" class="layui-form-label"></label>
                    <div class="layui-input-inline layui-word-aux" style="width: 300px;">
                    请输入9位组织机构代码或三证合一后18位统一社会信用代码
                    </div>
                   
                </div>
                
                
                
                <div class="layui-form-item">
                        <label  class="layui-form-label">营业期限:</label>
                        <div class="layui-input-inline" style="width: 110px;">
                            <input type="text"  id="businessTermStart" name="businessTermStart" class="layui-input"  placeholder=" 营业开始期限 ">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
		                   - 
		                </div>
                        <div class="layui-input-inline" style="width: 110px;">
                            <input type="text"  id="businessTermEnd" name="businessTermEnd" class="layui-input"  placeholder=" 营业结束期限 ">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
		                  <span class="x-red">*</span>
		                </div>
                </div>
                <div class="layui-form-item">
                        <label for="businessScope" class="layui-form-label">经营范围:</label>
                        <div class="layui-input-inline" style="width: 300px;">
                        		<textarea id="businessScope" name="businessScope" class="layui-textarea"></textarea>
                        </div>
                        <div class="layui-form-mid layui-word-aux">
		                  <span class="x-red">*</span>
		              </div>
                </div>
                <div class="layui-form-item">
                        <label for="businessLicenseUrl" class="layui-form-label">营业执照:</label>
                        <div class="layui-input-inline add_mebtn">
	                            <div class="user-file-img upfile" lay-data="{url: '/admin/upload/fileupload.htm?module=license',showImgId:'license',inputId:'businessLicenseUrl'}">
	                            		<img src="" alt="" id="license"/>
	                            </div>
                            <input type="hidden" name="businessLicenseUrl" id="businessLicenseUrl" value=""/>
                        </div>
                        <div class="layui-form-mid layui-word-aux">
		                  <span class="x-red">*</span>支持.jpg .jpeg .bmp .gif .png,大小不超过2M。
		               </div>
                </div>
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
				  <legend>法人信息</legend>
				</fieldset>
                
                <div class="layui-form-item">
                    <label  for="legalPerson" class="layui-form-label">法人姓名:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="legalPerson" name="legalPerson" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入法人姓名">

                    </div>
                </div>
                <div class="layui-form-item">
                        <label for="idcard" class="layui-form-label">身份证号:</label>
                        <div class="layui-input-inline">
                            <input type="text" id="idcard" name="idcard" lay-verify="idcard" autocomplete="off" class="layui-input" placeholder="请输入身份证">
                        </div>
                </div>
                <div class="layui-form-item">
	                <label class="layui-form-label">法人身份证:</label>
	                <div class="layui-input-inline add_mebtn">
	                    <div class="user-file-img upfile"  lay-data="{url: '/admin/upload/fileupload.htm?module=idcard',showImgId:'frontImg',inputId:'idcardFront'}">
	                    		<img src="" alt="" id="frontImg"/>
	                    </div>
	                    <input type="hidden" name="idcardFront" id="idcardFront" value="" class="user-file-input"/>
	                    <p class="add_titps">正面照</p>
	                </div>
	                <div class="layui-input-inline add_mebtn">
	                    <div class="user-file-img upfile" lay-data="{url: '/admin/upload/fileupload.htm?module=idcard',showImgId:'backImg',inputId:'idcardBack'}">
	                    		<img src="" alt="" id="backImg"/>
	                    </div>
	                    <input type="hidden" name="idcardBack" id="idcardBack" value="" class="user-file-input"/>
	                    <p class="add_titps">反面照</p>
	                </div>
                </div>
                
                <fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
				  <legend>登陆账户</legend>
				</fieldset>
				
				<div class="layui-form-item">
                    <label  for="legalPerson" class="layui-form-label">登陆账户:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="userLoginId" name="userLoginId" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入代理商登录账户">

                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="idcard" class="layui-form-label">登陆密码:</label>
                    <div class="layui-input-inline">
                        <input type="password" id="password" name="password" lay-verify="" autocomplete="off" class="layui-input" placeholder="请输入代理商登录密码">
                    </div>
                </div>
                
                <div class="layui-form-item">
	              <label  class="layui-form-label"></label>
		          <button  class="layui-btn" lay-filter="add" lay-submit="">立即创建</button>
		        </div>
		      </form>
            </div>
        </div>
    
     <script>
     	//全局定义一次, 加载formSelects
	    layui.config({
	        base: '/asset/plugin/formSelects/dist/' //此处路径请自行处理, 可以使用绝对路径
	    }).extend({
	        formSelects: 'formSelects-v4'
	    });
     
        layui.use(['form','layer','laydate','upload','formSelects'], function(){
            $ = layui.jquery;
          var form = layui.form ,layer = layui.layer,laydate = layui.laydate,upload = layui.upload,formSelects = layui.formSelects;
          
          laydate.render({
		    elem: '#businessTermStart' //指定元素
		  });
          
          laydate.render({
		    elem: '#businessTermEnd' //指定元素
		  });
		  
		  
		  formSelects.data('select15_2', 'server', {
	            url: '/asset/geo.json',
	            linkage: true,
	            linkageWidth: 130
	        });
		  
		  
		    var uploadInst = upload.render({
			    elem: '.upfile',
			    url: '/admin/upload/fileupload.htm?module=idcard',
			    
			    done: function(res,index, upload){
			      
			      console.log(res);
			      if(res.code == 1){
			      	 var data = res.data;
			      	 $("#" + this.showImgId + "").attr('src',data.fileurl);
			      	 $("#" + this.inputId + "").val(data.filepath);
			      
			     	 layer.msg('上传成功');
			      }else{
			      	layer.msg('上传失败');
			      }
			      
			      
			    }, error: function(){
			    		layer.msg('上传失败');
			        uploadInst.upload();
			      
			    }
			});
		  
		  
        

          //监听提交
          form.on('submit(add)', function(data){
            console.log(data);
            var field = data.field;
            var geos = field.geos;
            if(!geos){
            		layer.msg('请选择区域');
            		return false;
            }
            var geoArray = geos.split("/")
            
            field.provinceId = geoArray[0];
            field.cityId = geoArray[1];
            field.areaId = geoArray[2];
            
            $.ajax({
      			type:"POST", 
      			url:"/admin/agent/create.htm",
      			data:data.field ,
      			success:function(result) {
		      
		      		if(result.code=='1'){
		      			var data = result.data;
		      			layer.alert("创建成功", {icon: 6},function () {
			                // 获得frame索引
			                //window.parent.location.reload();
			                //var index = parent.layer.getFrameIndex(window.name);
			                //关闭当前frame
			                //parent.layer.close(index);
			                location.href="/admin/agent/list.htm;
			            });
		      		}else{
		      		 	layer.msg(result.msg);
		      		}
		      
		    	 	} 
		    }); 
            
            
            return false;
          });
          
        });
    </script>
     
</body>
</html>